package cn.edu.zjicm.wordsnet_d.util;

/**
 * 数据验证
 * @author cnting
 *
 */
public class DataValidator {
	//EditText内容是否为空
	public static boolean EditIsNull(String text){
		if(text.length()==0){
			return true;
		}else{
			return false;
		}
	}
	
//	static String regular1 = "^[a-zA-Z0-9_\\-]{1,}[a-zA-Z0-9_\\-.]*[a-zA-Z0-9_\\-]{1,}@[a-zA-Z0-9_\\-]{1,}\\.[a-zA-Z0-9_\\-.]{1,}$";
	
//	static String regular2 = "^(?!\\.)(?!.*\\.$)[a-zA-Z0-9_\\-.]{1,}@[a-zA-Z0-9_\\-]{1,}\\.[a-zA-Z0-9_\\-.]{1,}$";
	
	static String prefixRegular = "^(?!\\.)(?!.*\\.$)[a-zA-Z0-9_\\-.]{1,}$";
	static String suffixRegular = "^[a-zA-Z0-9_\\-]{1,}\\.[a-zA-Z0-9_\\-.]{1,}$";
	
	//邮箱格式是否正确
	public static boolean EmailIsValidate(String text){
		String[] str = text.split("@");
		if(str.length!=2){
			return false;
		}else{
			if(str[0].matches(prefixRegular)){
				if(str[1].matches(suffixRegular)){
					return true;
				}else{
					return false;
				}
			}else{
				return false;
			}
		}
	}
	//密码格式是否正确
	public static boolean PwdIsValidate(String text){
		if(!text.matches("[0-9a-zA-Z]{6,16}")){
			return false;
		}else{
			return true;
		}
	}
	//两次密码是否匹配
	public static boolean PwdIsMatch(String pwd,String pwd2){
		if(!pwd.equals(pwd2))
			return false;
		else 
			return true;
	}
}
